package interfacePackage;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.GridBagLayout;
import javax.swing.SwingConstants;
import java.awt.GridBagConstraints;

import javax.swing.ButtonGroup;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.border.BevelBorder;
import java.lang.String;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JRadioButton;

import mapPackage.tailleVille.SGrande;
import mapPackage.tailleVille.SMoyenne;
import mapPackage.tailleVille.SPetite;
import mapPackage.tailleVille.STailleVille;
import mapPackage.typeRoute.SAutoroute;
import mapPackage.typeRoute.SDepartementale;
import mapPackage.typeRoute.SNationale;
import mapPackage.typeRoute.SRouteIndeterminee;
import mapPackage.typeRoute.STypeRoute;

public class FramePopupAjouterRoute extends JFrame implements ActionListener {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabelAjouterVille = null;

	private JPanel jPanelAjouterVilleInterieur = null;

	private JLabel jLabelNomVille = null;

	private JLabel jLabelTailleVille = null;

	private JTextField jTextFieldNomVille = null;
	private ButtonGroup bgroupTouriste= new ButtonGroup();  //  @jve:decl-index=0:
	private ButtonGroup bgroupOuverte = new ButtonGroup();  //  @jve:decl-index=0:
	
	private JComboBox jComboBoxTailleVille = null;

	private JButton jButtonAjouter = null;

	private JButton jButtonAnnuler = null;

	private static String CLIC_BOUTON_AJOUTER = "CLIC_BOUTON_AJOUTER";  //  @jve:decl-index=0:
	private static String CLIC_BOUTON_ANNULER = "CLIC_BOUTON_ANNULER";  //  @jve:decl-index=0:
	public static String FRAME_POPUP_AJOUTER_ROUTE_FERMEE = "FRAME_POPUP_AJOUTER_ROUTE_FERMEE";  //  @jve:decl-index=0:

	private JLabel jLabelOuverte = null;

	private JRadioButton jRadioButtonOuverteOui = null;

	private JRadioButton jRadioButtonOuverteNon = null;

	/**
	 * This is the default constructor
	 */
	public FramePopupAjouterRoute() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(385, 263);
		this.setContentPane(getJContentPane());
		this.setTitle("Ajouter une route");

		this.addWindowListener( new WindowAdapter() {
             // This window listener responds when the user
             // clicks the window's close box by giving the
             // user a chance to change his mind.
          public void windowClosing(WindowEvent evt) {
        	  PanelAdministrationRoutes.getInstance().actionPerformed(new ActionEvent(evt.getWindow(), ActionEvent.ACTION_PERFORMED, FRAME_POPUP_AJOUTER_ROUTE_FERMEE));
          }
       });
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabelAjouterVille = new JLabel();
			jLabelAjouterVille.setBounds(new Rectangle(18, 13, 146, 20));
			jLabelAjouterVille.setText("Ajouter une route");
			jLabelAjouterVille.setFont(new Font("Tahoma", Font.BOLD, 16));
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setBackground(new Color(163, 163, 224));
			jContentPane.add(jLabelAjouterVille, null);
			jContentPane.add(getJPanelAjouterVilleInterieur(), null);
			jContentPane.add(getJButtonAjouter(), null);
			jContentPane.add(getJButtonAnnuler(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanelAjouterVilleInterieur	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelAjouterVilleInterieur() {
		if (jPanelAjouterVilleInterieur == null) {
			jLabelOuverte = new JLabel();
			jLabelOuverte.setBounds(new Rectangle(28, 75, 65, 21));
			jLabelOuverte.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelOuverte.setText("Ouverte :");
			jLabelOuverte.setPreferredSize(new Dimension(100, 30));
			jLabelTailleVille = new JLabel();
			jLabelTailleVille.setPreferredSize(new Dimension(100, 30));
			jLabelTailleVille.setText("Type :");
			jLabelTailleVille.setSize(new Dimension(49, 23));
			jLabelTailleVille.setLocation(new Point(44, 45));
			jLabelTailleVille.setHorizontalAlignment(SwingConstants.CENTER);
			jLabelNomVille = new JLabel();
			jLabelNomVille.setPreferredSize(new Dimension(100, 30));
			jLabelNomVille.setText("Nom :");
			jLabelNomVille.setSize(new Dimension(51, 18));
			jLabelNomVille.setLocation(new Point(44, 19));
			jLabelNomVille.setHorizontalAlignment(SwingConstants.CENTER);
			jPanelAjouterVilleInterieur = new JPanel();
			jPanelAjouterVilleInterieur.setLayout(null);
			jPanelAjouterVilleInterieur.setBounds(new Rectangle(15, 53, 345, 115));
			jPanelAjouterVilleInterieur.setBackground(new Color(209, 209, 240));
			jPanelAjouterVilleInterieur.setBorder(BorderFactory.createLineBorder(new Color(38, 38, 115), 2));
			jPanelAjouterVilleInterieur.add(jLabelNomVille);
			jPanelAjouterVilleInterieur.add(jLabelTailleVille);
			jPanelAjouterVilleInterieur.add(getJTextFieldNomVille());
			jPanelAjouterVilleInterieur.add(getJComboBoxTailleVille());
			jPanelAjouterVilleInterieur.add(jLabelOuverte, null);
			jPanelAjouterVilleInterieur.add(getJRadioButtonOuverteOui(), null);
			jPanelAjouterVilleInterieur.add(getJRadioButtonOuverteNon(), null);
		}
		return jPanelAjouterVilleInterieur;
	}

	/**
	 * This method initializes jTextFieldNomVille	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldNomVille() {
		if (jTextFieldNomVille == null) {
			jTextFieldNomVille = new JTextField();
			jTextFieldNomVille.setPreferredSize(new Dimension(200, 20));
			jTextFieldNomVille.setBounds(new Rectangle(97, 19, 118, 21));
		}
		return jTextFieldNomVille;
	}

	/**
	 * This method initializes jComboBoxTailleVille	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxTailleVille() {
		if (jComboBoxTailleVille == null) {
			jComboBoxTailleVille = new JComboBox();
			jComboBoxTailleVille.setPreferredSize(new Dimension(200, 10));
			jComboBoxTailleVille.setSize(new Dimension(118, 21));
			jComboBoxTailleVille.setLocation(new Point(97, 45));
			jComboBoxTailleVille.addItem(	SAutoroute.getInstance().getNom());
			jComboBoxTailleVille.addItem(	SNationale.getInstance().getNom());
			jComboBoxTailleVille.addItem(	SDepartementale.getInstance().getNom());
		}
		return jComboBoxTailleVille;
	}

	/**
	 * This method initializes jButtonAjouter	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAjouter() {
		if (jButtonAjouter == null) {
			jButtonAjouter = new JButton();
			jButtonAjouter.setBounds(new Rectangle(112, 182, 74, 30));
			jButtonAjouter.setFont(new Font("Tahoma", 1, 11));
			jButtonAjouter.setForeground(new Color(38, 38, 115));
			jButtonAjouter.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			jButtonAjouter.setActionCommand(CLIC_BOUTON_AJOUTER);
			jButtonAjouter.setText("Ajouter");
			jButtonAjouter.setBackground(new Color(209, 209, 240));
			jButtonAjouter.addActionListener(this);
		}
		return jButtonAjouter;
	}

	/**
	 * This method initializes jButtonAnnuler	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAnnuler() {
		if (jButtonAnnuler == null) {
			jButtonAnnuler = new JButton();
			jButtonAnnuler.setFont(new Font("Tahoma", 1, 11));
			jButtonAnnuler.setForeground(new Color(38, 38, 115));
			jButtonAnnuler.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			jButtonAnnuler.setActionCommand(CLIC_BOUTON_ANNULER);
			jButtonAnnuler.setText("Annuler");
			jButtonAnnuler.setSize(new Dimension(74, 30));
			jButtonAnnuler.setLocation(new Point(192, 182));
			jButtonAnnuler.setBackground(new Color(209, 209, 240));
			jButtonAnnuler.addActionListener(this);
		}
		return jButtonAnnuler;
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals(CLIC_BOUTON_AJOUTER)) {
			boolean isOuverte = false;
			if (jRadioButtonOuverteOui.isSelected()) {
				isOuverte = true;
			}
			STypeRoute taille = SDepartementale.getInstance();
			if (jComboBoxTailleVille.getSelectedItem().toString().equals("Autoroute")) {
				taille = SAutoroute.getInstance();
			}
			if (jComboBoxTailleVille.getSelectedItem().toString().equals("Nationale")) {
				taille = SNationale.getInstance();
			}
			if (jComboBoxTailleVille.getSelectedItem().toString().equals("Departementale")) {
				taille = SDepartementale.getInstance();
			}
			PanelAdministrationRoutes.getInstance().ajouterRoute(jTextFieldNomVille.getText(), taille, isOuverte);
			TobtobFenetre.getInstance().setEnabled(true);
			this.dispose();
		}
		else {
			if (e.getActionCommand().equals(CLIC_BOUTON_ANNULER)) {
				TobtobFenetre.getInstance().setEnabled(true);
				this.dispose();
			}
		}
	}

	/**
	 * This method initializes jRadioButtonOuverteOui	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButtonOuverteOui() {
		if (jRadioButtonOuverteOui == null) {
			jRadioButtonOuverteOui = new JRadioButton();
			jRadioButtonOuverteOui.setText("oui");
			jRadioButtonOuverteOui.setSize(new Dimension(42, 24));
			jRadioButtonOuverteOui.setLocation(new Point(95, 74));
			jRadioButtonOuverteOui.setBackground(new Color(209, 209, 240));
			bgroupOuverte.add(jRadioButtonOuverteOui);
			jRadioButtonOuverteOui.setSelected(true);
		}
		return jRadioButtonOuverteOui;
	}

	/**
	 * This method initializes jRadioButtonOuverteNon	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButtonOuverteNon() {
		if (jRadioButtonOuverteNon == null) {
			jRadioButtonOuverteNon = new JRadioButton();
			jRadioButtonOuverteNon.setText("non");
			jRadioButtonOuverteNon.setSize(new Dimension(46, 24));
			jRadioButtonOuverteNon.setLocation(new Point(151, 76));
			jRadioButtonOuverteNon.setBackground(new Color(209, 209, 240));
			bgroupOuverte.add(jRadioButtonOuverteNon);
		}
		return jRadioButtonOuverteNon;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
